package com.pubinfo.passbook.data.quartz.service.impl;

import com.pubinfo.passbook.common.entity.TSourceArtificial;
import com.pubinfo.passbook.common.mapper.TSourceArtificialMapper;
import com.pubinfo.passbook.common.service.mss.HttpService;
import com.pubinfo.passbook.common.service.ruler.CheckService;
import com.pubinfo.passbook.data.quartz.service.ManualInvoiceReimbursement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author litiewang
 * @version 1.0
 * @date 2021/12/14 8:52
 */
@Service
public class ManualInvoiceReimbursementImpl implements ManualInvoiceReimbursement {
  @Autowired
  TSourceArtificialMapper artificialMapper;
  @Autowired
  CheckService checkService;
  @Autowired
  HttpService httpService;
  @Override
  public void autoManualReimbursement(List<String> ids) {
    List<TSourceArtificial> artificialList = artificialMapper.findAutoArtificialReimbursement(ids);
    //按公司进行分组
    Map<String, List<TSourceArtificial>> cityMap = artificialList
        .stream()
        .filter(tSourceArtificial -> tSourceArtificial.getNsrsbh() != null)
        .collect(Collectors.groupingBy(TSourceArtificial::getNsrsbh));
    for (Map.Entry<String, List<TSourceArtificial>> mapItem : cityMap.entrySet()) {
      //// 如果当前未到报销时间,则不进行报账.
      //if (checkService.isReimbursementDate(mapItem.getKey())) {
      //再按用户进行分组
      Map<String, List<TSourceArtificial>> userMap = mapItem.getValue().stream().collect(Collectors.groupingBy(TSourceArtificial::getAcct));
      for (Map.Entry<String, List<TSourceArtificial>> userMapItem : userMap.entrySet()) {
        List<TSourceArtificial> userArtificialList = userMapItem.getValue();
        List<TSourceArtificial> hospitalizationList = userArtificialList.stream().filter(e -> e.getType() != null && e.getType() == 330602).collect(Collectors.toList());
        List<TSourceArtificial> outpatientList = userArtificialList.stream().filter(e -> e.getType() != null && e.getType() == 330601).collect(Collectors.toList());
        httpService.manualData(hospitalizationList, false,null);
        httpService.manualData(outpatientList, false,null);
      }
    
    }
    
    // manualData(hospitalizationList);
    //  manualData(outpatientList);
  }
  
}
